package com.person.leetcode.editor.cn;

import java.util.HashMap;

/**
  * 169.多数元素
  * 2022-07-15 17:32:54
**/
public class Sequence_0169_MajorityElement {
    public static void main(String[] args) {
        Solution solution = new Sequence_0169_MajorityElement().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
        //时间 On 空间 O1
    public int majorityElement(int[] nums) {
        HashMap<Integer, Integer> num = new HashMap<>();
        for (int n : nums) {
            if (num.containsKey(n)){
                num.put(n,num.get(n)+1);
            }else{
                num.put(n,1);
            }
        }
        System.out.println(num);
        int maxCount = 0;
        int max = 0;
        for (Integer i : num.keySet()) {
            if (num.get(i) > maxCount){
                max = i;
                maxCount = num.get(i);
            }
        }
        return max;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}